package dao.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import pojo.Customer;
import util.DBUtil;

public class UpdateDao {
	public static int updateCustomer(Customer customer){
		String sql = "update customer set sal =?,birth =?,sex =?,name =?where id =?";
		PreparedStatement pst = null;
		int m = 0;
		Connection con = null;
		try {
			con = DBUtil.createConnection();
			pst=con.prepareStatement(sql);
			pst.setDouble(1,customer.getSal());
			pst.setDate(2,new java.sql.Date(customer.getBirth().getTime()));
			pst.setBoolean(3,customer.getSex());
			pst.setString(4, customer.getCname());
			pst.setInt(5, customer.getId());
			m = pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.close(con,pst,null);
		}
		return m;
	}
	public static int updateHobby(int m,String[] favs){
		DeleteDao.deleteHobby(m);
		
		for(String fav:favs){
			m = AddDao.addHobby(m, fav);
		}
		return m;
	}
//	public static int findId(int id){
//		Connection con = null;
//		String sql = "select id,name from customer";
//		PreparedStatement pst = null;
//		ResultSet rs = null;
//		try {
//			con = DBUtil.createConnection();
//			pst=con.prepareStatement(sql);
//			rs = pst.executeQuery();
//			while(rs.next()){
//				if(rs.getInt("id")==id){
//				id = rs.getInt("id");
//				}
//			}
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}finally{
//			DBUtil.close(con,pst,rs);
//		}
//		return id;
//	}
}
